/**
 * 
 */
package org.jin.vote.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zhaom
 *
 */
@Controller
@SessionAttributes(names= {"userName"})
public class LoginController {
	@GetMapping("/login")
	public ModelAndView getLoginForm() {
		ModelAndView modelAndView = new ModelAndView("login");

		return modelAndView;
	}

	@PostMapping("/login")
	public ModelAndView loginConfirm(String userName, String password) {
		ModelAndView modelAndView = new ModelAndView();
		
		if(userName!=null && userName.equals("admin") && password!=null && password.equals("111")) {
			modelAndView.setViewName("index");
			modelAndView.addObject("userName", userName);
		} else {
			modelAndView.setViewName("redirect:/login");
		}
		
		return modelAndView;
	}
}
